package com.qczl.pme.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qczl.pme.dao.TopicDao;
import com.qczl.pme.entity.PMETopic;
import com.qczl.pme.service.TopicService;
import com.qczl.pme.vo.TopicVo;

/**
 * 主题类型业务逻辑层实现类
 * 
 * @author SongR
 *
 */
@Service
public class TopicServiceImpl implements TopicService {

	@Autowired
	TopicDao dao;

	/**
	 * 获取主题
	 */
	@Override
	public List<TopicVo> getTopicV1(int type, int start, int size) throws Exception {
		List<PMETopic> topicArray = dao.findP("from PMETopic where pid=" + type + " and status=0 order by sort", start,
				size);
		List<TopicVo> voArray = new ArrayList<TopicVo>();
		for (PMETopic t : topicArray) {
			TopicVo vo = new TopicVo();
			BeanUtils.copyProperties(t, vo);
			voArray.add(vo);
		}
		return voArray;
	}

	/**
	 * 获取主题数
	 */
	@Override
	public Long countTopicV1(int type) throws Exception {
		return dao.count("select count(*) from PMETopic where pid=" + type);
	}

	/**
	 * 根据主题获取类型
	 */
	@Override
	public List<TopicVo> getTypeV1(String pid, int start, int size) throws Exception {
		List<PMETopic> topicArray = dao.findP("from PMETopic where pid=" + pid + " and status=0 order by sort", start,
				size);
		List<TopicVo> voArray = new ArrayList<TopicVo>();
		for (PMETopic t : topicArray) {
			TopicVo vo = new TopicVo();
			BeanUtils.copyProperties(t, vo);
			voArray.add(vo);
		}
		return voArray;
	}

	/**
	 * 获取类型数
	 */
	@Override
	public Long countTypeV1(String pid) throws Exception {
		return dao.count("select count(*) from PMETopic where pid=" + pid);
	}

}
